home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / jpegagasrc / jpegaga / scalefit.c < prev    next >
C/C++ Source or Header  |  1995-11-08  |  4KB  |  163 lines

  1. /* Find best scale to fit on the screen */
  2. /* written by Günther Röhrich */
  3. /* for jpegAGA 2.x */
  4.  
  5. #define __NOLIBBASE__
  6. #include <proto/graphics.h>
  7. #include <proto/exec.h>
  8.  
  9. #include <graphics/modeid.h>
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "jpeglib.h"
  14. #include "WBFlags.h"
  15.  
  16. #define HAM8 1
  17. #define TOLERANCE 35
  18.  
  19. extern struct WBFlags WBFlags;
  20.  
  21. extern struct GfxBase *GfxBase;
  22.  
  23. ULONG ScaleFitDisplayID=0;
  24.  
  25. int FindScaleFit(JDIMENSION width, JDIMENSION height, ULONG Mode)
  26. {
  27.  struct DimensionInfo querydims;
  28.  ULONG MyDisplayID, NoSUPER72;
  29.  JDIMENSION scrwidth, scrheight;
  30.  JDIMENSION VGAwidth, VGAheight;
  31.  int scale;
  32.  
  33.  ScaleFitDisplayID = 0;
  34.  
  35.  if(!GfxBase)
  36.  {
  37.    if(!(GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",39)))
  38.    {
  39.      printf("Could not open graphics.library V39 or higher.\n");
  40.      return -1;
  41.    }
  42.  }
  43.  
  44.  /* check if SUPER72 mode is available */
  45.  
  46.  NoSUPER72 = ModeNotAvailable(SUPER72_MONITOR_ID | SUPERHAMLACE_KEY);
  47.  
  48.  
  49.  MyDisplayID = HIRESLACE_KEY;
  50.  
  51.  if(WBFlags.VGAenable)
  52.  {
  53.    if(ModeNotAvailable(VGAPRODUCT_KEY))
  54.    {
  55.      return -1;
  56.    }
  57.    else
  58.    {
  59.      if(GetDisplayInfoData(NULL, (UBYTE *)&querydims, sizeof(querydims),DTAG_DIMS,VGAPRODUCT_KEY))
  60.      {
  61.        /* allow 10 pixels tolerance */
  62.        VGAwidth  = (JDIMENSION)querydims.StdOScan.MaxX+TOLERANCE;
  63.        VGAheight = (JDIMENSION)querydims.StdOScan.MaxY+TOLERANCE;
  64.      }
  65.    }
  66.  
  67.    MyDisplayID = VGAPRODUCT_KEY;
  68.    if(WBFlags.SUPER72enable && !NoSUPER72) MyDisplayID = SUPER72_MONITOR_ID | SUPERLACE_KEY;
  69.  }
  70.  
  71.  if(GetDisplayInfoData(NULL, (UBYTE *)&querydims, sizeof(querydims),DTAG_DIMS,MyDisplayID))
  72.  {
  73.    /* allow 34 pixels tolerance */
  74.    scrwidth  = (JDIMENSION)querydims.StdOScan.MaxX+TOLERANCE;
  75.    scrheight = (JDIMENSION)querydims.StdOScan.MaxY+TOLERANCE;
  76.    /* printf("Screen width:  %d, height: %d\n", scrwidth-TOLERANCE+1, scrheight-TOLERANCE+1); */
  77.    /* printf("Picture width: %d, height: %d\n", width, height); */
  78.    /* printf("VGA width:     %d, height: %d\n", VGAwidth-TOLERANCE+1, VGAheight-TOLERANCE+1); */
  79.  }
  80.  else return -1;
  81.  
  82.  for(scale=1; scale<8; scale = scale<<1)
  83.  {
  84.    if((width / scale <= scrwidth) && (height / scale <= scrheight)) break;
  85.  }
  86.  
  87.  /* Find the right screenmode */
  88.  
  89.  
  90.  /* SUPER72 is the default, when available */
  91.  
  92.  if(WBFlags.SUPER72enable && !NoSUPER72 && WBFlags.VGAenable)
  93.  {
  94.    if(Mode == HAM8)
  95.    {
  96.      ScaleFitDisplayID = SUPER72_MONITOR_ID | SUPERHAMLACE_KEY;
  97.    }
  98.    else
  99.    {
  100.      ScaleFitDisplayID = SUPER72_MONITOR_ID | SUPERLACE_KEY;
  101.    }
  102.  }
  103.  
  104.  
  105.  /* Check for fit on a VGA screen */
  106.  
  107.  if(WBFlags.VGAenable)
  108.  {
  109.    /* check for fit on a LORES screen */
  110.    if((VGAwidth / 2 >= width / scale) && (VGAheight / 2 >= height / scale))
  111.    {
  112.      if(Mode == HAM8)
  113.      {
  114.        ScaleFitDisplayID = VGALORESHAMDBL_KEY;
  115.      }
  116.      else
  117.      {
  118.        ScaleFitDisplayID = VGALORESDBL_KEY;
  119.      }
  120.    }
  121.    else if((VGAwidth >= width / scale) && (VGAheight >= height / scale) || !WBFlags.SUPER72enable)
  122.    {
  123.      if(Mode == HAM8)
  124.      {
  125.        ScaleFitDisplayID = VGAPRODUCTHAM_KEY;
  126.      }
  127.      else
  128.      {
  129.        ScaleFitDisplayID = VGAPRODUCT_KEY;
  130.      }
  131.    }
  132.  }
  133.  
  134.  if(ScaleFitDisplayID == 0)
  135.  {
  136.    /* check for fit on a LORES screen */
  137.    if((scrwidth / (scale * 2) >= width) && (scrheight / (scale * 2) >= height))
  138.    {
  139.      if(Mode == HAM8)
  140.      {
  141.        ScaleFitDisplayID = HAM_KEY;
  142.      }
  143.      else
  144.      {
  145.        ScaleFitDisplayID = LORES_KEY;
  146.      }
  147.    }
  148.    else
  149.    {
  150.      if(Mode == HAM8)
  151.      {
  152.        ScaleFitDisplayID = HIRESHAMLACE_KEY;
  153.      }
  154.      else
  155.      {
  156.        ScaleFitDisplayID = HIRESLACE_KEY;
  157.      }
  158.    }
  159.  }
  160.  
  161.  return scale;
  162. }
  163.